#!/bin/bash
# Git Hooks 动态配置系统 - 快速开始脚本

set -e

echo "=========================================="
echo "Git Hooks 动态配置系统 - 快速开始"
echo "=========================================="

# 检查 Python 版本
echo "检查 Python 版本..."
python3 --version || {
    echo "错误: 需要 Python 3.7 或更高版本"
    exit 1
}

# 检查 Git 仓库
echo "检查 Git 仓库..."
if [ ! -d ".git" ]; then
    echo "错误: 当前目录不是 Git 仓库"
    echo "请先运行: git init"
    exit 1
fi

# 安装依赖
echo "安装 Python 依赖..."
pip3 install PyYAML pathlib2 || {
    echo "警告: 无法安装依赖，请手动安装: pip3 install PyYAML pathlib2"
}

# 创建必要目录
echo "创建项目目录..."
mkdir -p config plugins logs examples docs

# 复制示例配置
echo "设置示例配置..."
if [ ! -f "config/hooks.yaml" ]; then
    cp examples/basic-config.yaml config/hooks.yaml
    echo "已创建基础配置文件: config/hooks.yaml"
fi

# 安装系统
echo "安装 Git Hooks..."
python3 tools/install.py --install || {
    echo "错误: 安装失败"
    exit 1
}

# 验证安装
echo "验证安装..."
python3 tools/install.py --status

# 显示使用说明
echo ""
echo "=========================================="
echo "安装完成！"
echo "=========================================="
echo ""
echo "使用说明:"
echo "1. 编辑配置文件: config/hooks.yaml"
echo "2. 查看配置: python3 tools/config.py show"
echo "3. 验证配置: python3 tools/config.py validate"
echo "4. 查看日志: tail -f .git/hooks-controller.log"
echo ""
echo "示例命令:"
echo "  # 查看系统状态"
echo "  python3 tools/install.py --status"
echo ""
echo "  # 查看配置"
echo "  python3 tools/config.py show"
echo ""
echo "  # 启用/禁用 Hook"
echo "  python3 tools/config.py enable pre-commit"
echo "  python3 tools/config.py disable pre-commit"
echo ""
echo "  # 添加任务"
echo "  python3 tools/config.py add-task pre-commit --name '新任务' --type lint"
echo ""
echo "  # 卸载系统"
echo "  python3 tools/install.py --uninstall"
echo ""
echo "更多信息请查看: docs/README.md"
echo "=========================================="
